// 示例：使用组合式 API 风格（推荐）
import { defineStore } from 'pinia'
import { ref } from 'vue'
import axios from '../api/axios'

export const useProjectStore = defineStore('project', () => {
  const projects = ref([]) // 响应式数据

  // 可选：定义操作数据的方法
  const setProjects = (newProjects) => {
    projects.value = newProjects
  }

  return { projects, setProjects }
})

export const getProject = async (id) => {
  const project = ref([])
  try {
    const response = await axios.get('/project/project', {
      params: {
        pid: id
      }
    })
    if (response.data.code == 200) {
      project.value = response.data.data || []
    }
  } catch (error) {
    ElMessage.error('获取项目信息失败');
  }
  return { project }
}